import { WeApp } from '../../common/common';
import * as wux from '../../assets/components/wux';
import httpClient from '../../common/http-client';
import { config } from '../../etc/config';
import wxService from '../../common/wxService'
import utils from '../../utils/utils'
import { prompt } from '../../assets/components/wux';
import { Goods } from '../../model/goods';
// import  * as filter from '../../common/filter';

const app: WeApp = getApp() as WeApp;
interface AppIndexPageData {
	navs?: any,
	indicatorDots?: boolean,
	autoplay?: boolean,
	rmSwiperCurrent: number,
	isLoadSucc?: boolean
}
interface AppIndexPage extends IPage {
}

class AppIndexPage {
	private animation;
	public data: AppIndexPageData = {
		indicatorDots: false,
		autoplay: true,
		rmSwiperCurrent: 0,
		isLoadSucc: true,
	}

	public navigateTo(e) {
		utils.navigateTo(e.currentTarget.dataset.id, e.currentTarget.dataset.type, e.currentTarget.dataset.tag);
	}

	public onLoad(options) {
		wxService.showLoading();
		this.getData().then(() => {
			utils.closeAllLoading();
		});
	}

	onPullDownRefresh() {
		wx.showNavigationBarLoading();
		this.getData().then(() => {
			utils.closeAllLoading();
		});
	};

	getData() {
		return httpClient.post<Goods>(config.goods.goods_list, null)
			.then((res) => {
				if (res.succeed) {
					this.setData({
						'goodsList': res.pageData.datas
					})
				} else {
					utils.showToastErr(res.msg);
				}
			}).catch(e => {

			});
	}



	errorTips() {
		this.setData({ 'isLoadSucc': false });
		utils.loadError(() => {
			wx.showNavigationBarLoading();
			this.onPullDownRefresh();
		})
	}

	rmSwiperChange(e) {
		this.setData({
			'rmSwiperCurrent': e.detail.current
		})
	}

	onShareAppMessage() {
		return {
			title: '集采演示版',
			desc: '集采电商平台，一站式企业化办公阳光采购，该版本专为客户演示、交流存起来!',
			path: '/pages/index/index'
		}
	}


}
Page(new AppIndexPage());

//Page(filter.default.identityFilter(AppIndexPage))